<nav class="navbar navbar-default">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="<%= root_path %>">蛋人商城</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="<%= root_path %>">Home <span class="sr-only">(current)</span></a></li>
      </ul>
      <%= form_tag search_products_path, method: :get, class: "navbar-form navbar-left" do %>
        <div class="form-group">
          <% if @category %>
            <input type="hidden" name="category_id" value="<%= @category.id %>" />
          <% end %>
          <input type="text" name="w" value="<%= params[:w] %>" class="form-control search-input" placeholder="<%= @category ? "在 #{@category.title} 下搜索.." : '搜索整站商品..' %>">
        </div>
        <button type="submit" class="btn btn-default">搜索</button>
      <% end %>
      <ul class="nav navbar-nav navbar-right">
        <li><%= link_to "购物车(#{@shopping_cart_count})", shopping_carts_path %></li>
        <% unless logged_in? %>
          <li><a href="<%= new_user_path %>">注册</a></li>
          <li><a href="<%= new_session_path %>">登录</a></li>
        <% else %>
          <li><a href="#">欢迎你, <%= current_user.username %></a></li>
          <li><%= link_to "退出", logout_path, method: :delete %></li>
        <% end -%>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">个人中心 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="<%= dashboard_orders_path %>">我的订单</a></li>
            <li><a href="<%= dashboard_addresses_path %>">我的收货地址</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="<%= dashboard_password_path %>">个人信息</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
